/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TMP100_DRIVER_H
#define __TMP100_DRIVER_H
 
#include "main.h"

#define TMP100_I2C                         I2C2
#define TMP100_I2C_CLK                     RCC_APB1Periph_I2C2
#define TMP100_I2C_SCL_PIN                 GPIO_Pin_10                 /* PB.10 */
#define TMP100_I2C_SCL_GPIO_PORT           GPIOB                       /* GPIOB */
#define TMP100_I2C_SCL_GPIO_CLK            RCC_APB2Periph_GPIOB
#define TMP100_I2C_SDA_PIN                 GPIO_Pin_11                 /* PB.11 */
#define TMP100_I2C_SDA_GPIO_PORT           GPIOB                       /* GPIOB */
#define TMP100_I2C_SDA_GPIO_CLK            RCC_APB2Periph_GPIOB
#define TMP100_I2C_DR                      ((uint32_t)0x40005810)

#define TMP100_DMA_CLK                     RCC_AHBPeriph_DMA1
#define TMP100_DMA_TX_CHANNEL              DMA1_Channel4
#define TMP100_DMA_RX_CHANNEL              DMA1_Channel5
#define TMP100_DMA_TX_TCFLAG               DMA1_FLAG_TC4
#define TMP100_DMA_RX_TCFLAG               DMA1_FLAG_TC5   

/** 
  * @brief  IOE DMA Direction  
  */ 
typedef enum
{
  TMP100_DMA_TX = 0,
  TMP100_DMA_RX = 1
}TMP100_DMADirection_TypeDef;

/** 
  * @brief  TSENSOR Status  
  */ 
typedef enum
{
  TMP100_OK = 0,
  TMP100_FAIL
}TMP100_Status_TypDef;
     
#define TMP100_FLAG_TIMEOUT         ((uint32_t)0x1000)
#define TMP100_LONG_TIMEOUT         ((uint32_t)(10 * TMP100_FLAG_TIMEOUT))    
    

/**
  * @brief  Block Size
  */
#define TMP100_REG_TEMP       0x00  /*!< Temperature Register of TMP100 */
#define TMP100_REG_CONF       0x01  /*!< Configuration Register of TMP100 */
#define TMP100_REG_THYS       0x02  /*!< Temperature Register of TMP100 */
#define TMP100_REG_TOS        0x03  /*!< Over-temp Shutdown threshold Register of TMP100 */
#define I2C_TIMEOUT         ((uint32_t)0x3FFFF) /*!< I2C Time out */
#define TMP100_ADDR_0         0b1001000   /*!< TMP100 address */
#define TMP100_ADDR_1         0b1001010   /*!< TMP100 address */
#define TMP100_ADDR_2         0b1001100   /*!< TMP100 address */
#define TMP100_ADDR_3         0b1001110   /*!< TMP100 address */
#define TMP100_I2C_SPEED      100000 /*!< I2C Speed */
  
void TMP100_DeInit(void);
void TMP100_Init(void);
ErrorStatus TMP100_GetStatus(uint8_t addr);
uint16_t TMP100_ReadTemp(uint8_t addr);
uint16_t TMP100_ReadReg(uint8_t RegName, uint8_t addr);
uint8_t TMP100_WriteReg(uint8_t RegName, uint16_t RegValue, uint8_t addr);
uint8_t TMP100_ReadConfReg(uint8_t addr);
uint8_t TMP100_WriteConfReg(uint8_t RegValue, uint8_t addr);
uint8_t TMP100_ShutDown(FunctionalState NewState, uint8_t addr);
void TMP100_LowLevel_Init(void);
void TMP100_LowLevel_DeInit(void);

#define TMP100_TIMEOUT_UserCallback()  TMP100_FAIL
 


#endif /* __TMP100_DRIVER_H */